<template>
    <div class="data">
        <!-- 地图容器 -->
        <div id="map" style="height:500px;"></div>
    </div>
</template>

<script>
import axios from '@/http/axios'
export default {
    data(){
      return {
          dataList:[
            {name:"南海诸岛",value:0},
            {name: '北京', value: 1000},
            {name: '天津', value: 200},
            {name: '上海', value: 231},
            {name: '重庆', value: 345},
            {name: '河北', value: 23},
            {name: '河南', value: 5},
            {name: '云南', value: 12},
            {name: '辽宁', value: 567},
            {name: '黑龙江', value: 34},
            {name: '湖南', value: 621},
            {name: '安徽', value: 2},
            {name: '山东', value: 212},
            {name: '新疆', value: 108},
            {name: '江苏', value: 121},
            {name: '浙江', value: 235},
            {name: '江西', value: 721},
            {name: '湖北', value: 231},
            {name: '广西', value: 231},
            {name: '甘肃', value: 876},
            {name: '山西', value: 91},
            {name: '内蒙古', value: 231},
            {name: '陕西', value: 9},
            {name: '吉林', value: 877},
            {name: '福建', value: 231},
            {name: '贵州', value: 231},
            {name: '广东', value: 231},
            {name: '青海', value: 231},
            {name: '西藏', value: 231},
            {name: '四川', value: 231},
            {name: '宁夏', value: 0},
            {name: '海南', value: 0},
            {name: '台湾', value: 0},
            {name: '香港', value: 0},
            {name: '澳门', value: 0}
        ]
      }
  },
  created(){
      this.findAll()
  },
  methods: {
    findAll(){
        axios({
            url:'http://121.199.29.84:8001/epidemic/pageQuery',
            methods: 'get',
            params:{
                page:1,
                pageSize:10000
            }
        }).then((res)=>{
            var shanghai = res.data.data.list.filter((item)=>{
                return item.province == '上海市'
            })
            var total = 0;
            shanghai.forEach((item)=>{
                total += item.confirmed
            })
            
            var data_shanghai = this.dataList.filter((item)=>{
                return item.name == '上海'
            })
            data_shanghai[0].value = total
            console.log(this.dataList)
        })
    },
    initEchart() {
        var myChart = echarts.init(document.getElementById('map'));
        var option = {
            tooltip: {
                //数据格式化
                formatter:function(params, callback){
                    return params.seriesName+'<br />'+params.name+'：'+params.value
                }
            },
            visualMap: {
                min: 0,
                max: 1000,
                left: 'left',
                top: 'bottom',
                text: ['高','低'],//取值范围的文字
                inRange: {
                    color: ['white', 'red']//取值范围的颜色
                },
                show:true//图注
            },
            geo: {
                map: 'china',
                roam: false,//不开启缩放和平移
                zoom:1.23,//视角缩放比例
                label: {
                    normal: {
                        show: true,
                        fontSize:'10',
                        color: 'rgba(0,0,0,0.7)'
                    }
                },
                itemStyle: {
                    normal:{
                        borderColor: 'rgba(0, 0, 0, 0.2)'
                    },
                    emphasis:{
                        areaColor: 'yellow',//鼠标选择区域颜色
                        shadowOffsetX: 0,
                        shadowOffsetY: 0,
                        shadowBlur: 20,
                        borderWidth: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            },
            // 鼠标悬浮提示框
            series : [
                {
                    name: '省份',
                    type: 'map',
                    geoIndex: 0,
                    data:this.dataList
                }
            ]
        };
        myChart.setOption(option);
        myChart.on('click', function (params) {
            alert(params.name);
        });
    }
  },
  mounted() {
    // 等待数据处理完毕之后再绘制地图
    setTimeout(()=>{
        this.initEchart();
    },3000)
  }

}
</script>